<template>
  <el-dialog
    @close="handleClose"
    @opened="handleOpened"
    :title="title || '修改星移计划'"
    width="880px"
    :visible.sync="visable"
  >
    <el-alert class="mb20" title="商户默认是打开的" type="warning"> </el-alert>

    <el-form-renderer
      label-width="140px"
      :content="content"
      @submit.native.prevent
      ref="queryForm"
      v-model="queryParams"
    >
    </el-form-renderer>
    <div slot="footer">
      <el-button @click="visable = false">取消</el-button>
      <el-button :loading="loadingBtn" type="primary" @click="handleSubmit"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import elFormRenderer from "../../../components/el-form-renderer/el-form-renderer";

export default {
  components: {
    elFormRenderer,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },

    title: {
      type: String,
    },
    componentData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  computed: {
    visable: {
      get: function (el) {
        return this.dialogFormVisible;
      },
      set: function (val) {
        this.$emit("update:dialogFormVisible", val);
      },
    },
    // queryParams: {
    //   get: function (el) {
    //     return this.componentData;
    //   },
    //   set: function (val) {
    //     this.$emit("update:componentData", val);
    //   },
    // },
  },
  data() {
    return {
      loadingBtn: false,
      // hasAgent: true, //标识是否请求区县级
      queryParams: {},
      content: [
        {
          el: {
            placeholder: "请输入商户号",
            clearable: true,
          },

          label: "商户号：",
          type: "input",
          id: "shopId",
          rules: [
            {
              required: true,
              message: "请输入商户号",
              trigger: "blur",
            },
          ],
        },
      ],
    };
  },
  methods: {
    handleClose() {
      this.loadingBtn = false;

      // this.$refs.queryForm.resetFields();
    },

    handleOpened() {
      this.queryParams = this.componentData;
    },

    handleSubmit() {
      console.log("inner");
      this.loadingBtn = true;
      this.$refs.queryForm.validate(async (valid) => {
        if (valid) {
          try {
            let params = this.$refs.queryForm.getFormValue();
            let { data } = await updatePaywayStatus({
              ...params,
            }).finally(() => {
              this.loadingBtn = false;
            });
            if (data.returnCode == "error" || data.returnCode == "fail") {
              this.$message.error(data.errorMsg || "未知异常");
              return;
            }
            //console.log(data);
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 5 * 1000,
            });
            this.visable = false;
          } catch (e) {
            console.log(e);
            this.loadingBtn = false;
          }
          return;
        }
        this.loadingBtn = false;
        this.$message({
          message: "请完善信息",
          type: "warning",
          duration: 5 * 1000,
        });
      });
    },
  },
};
</script>
